package com.xxh.dasongapp.security.config.handler;

import com.xxh.dasongapp.common.Result;
import com.xxh.dasongapp.common.ResultCode;

import com.xxh.dasongapp.security.utils.ResponseUtil;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户未登录处理类
 */
@Log4j2
@Component
public class UserAuthenticationEntryPointHandler implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception){
        log.info("用户未登录拦截");
        ResponseUtil.renderString(response, Result.error(ResultCode.UNAUTHORIZED.getCode(),"用户未登录或者登录已过期"));


    }
}
